package ru.spies.entities;

import java.io.Serializable;

import javax.persistence.*;

import java.util.List;

import static javax.persistence.FetchType.EAGER;
import static javax.persistence.CascadeType.ALL;


/**
 * The persistent class for the country database table.
 * 
 */
@Entity
@Table(name="country")
@NamedQuery(name="Country.findAll", query="SELECT c FROM Country c")
public class Country implements Serializable, ITableClass {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(unique=true, nullable=false)
	private Integer id;

	@Column(nullable=false, length=2147483647)
	private String name;

	@Column(length=2147483647)
	private String relation;

	//bi-directional many-to-one association to Department
	@OneToMany(mappedBy="country", fetch = EAGER, cascade = ALL)
	private List<Department> departments;

	//bi-directional many-to-one association to Task
	@OneToMany(mappedBy="country", fetch = EAGER, cascade = ALL)
	private List<Task> tasks;

	private Object paramForFindQuery=null;
	
	public Country() {
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRelation() {
		return this.relation;
	}

	public void setRelation(String relation) {
		this.relation = relation;
	}

	public List<Department> getDepartments() {
		return this.departments;
	}

	public void setDepartments(List<Department> departments) {
		this.departments = departments;
	}

	public Department addDepartment(Department department) {
		getDepartments().add(department);
		department.setCountry(this);

		return department;
	}

	public Department removeDepartment(Department department) {
		getDepartments().remove(department);
		department.setCountry(null);

		return department;
	}

	public List<Task> getTasks() {
		return this.tasks;
	}

	public void setTasks(List<Task> tasks) {
		this.tasks = tasks;
	}

	public Task addTask(Task task) {
		getTasks().add(task);
		task.setCountry(this);

		return task;
	}

	public Task removeTask(Task task) {
		getTasks().remove(task);
		task.setCountry(null);

		return task;
	}

	@Override
	public void setParamForFindQuery(Object param) {
		paramForFindQuery=param;		
	}

	@Override
	public Object getParamForFindQuery() {
		return paramForFindQuery;
	}

	@Override
	public ITableClass createThisObject() {
		return new Country();
	}

	@Override
	public String getQueryForFind() {
		return "SELECT x FROM Country x WHERE x.id = :param";
	}

}